package optimizers.ganeat.sin;

import java.util.Map;

import javax.swing.JPanel;

import model.OligoSystemGeneral;
import optimizers.commons.RunConfig;
import optimizers.ganeat.Constants;
import optimizers.ganeat.Individual;
import util.MyUtil;
import visualization.PlotExpData;
import fitness.SineFitness;

public class IndividualSin extends Individual {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected double[] sequenceConcentration = new double[2];

	public IndividualSin(Map<String, Integer> innovations,
			Map<String, String> nodeNames, int geneIndex, int indivIndex,
			RunConfig config) {
		super(innovations, nodeNames, geneIndex, indivIndex, config);
	}

	public IndividualSin(Map<String, Integer> innovations,
			Map<String, String> nodeNames, int geneIndex, int indivIndex,
			RunConfig config, String string) {
		super(innovations, nodeNames, geneIndex, indivIndex, config, string);
	}

	protected String getGoalStringName() {
		return "SinT";
	}

	@Override
	public JPanel displayTimeSereis() {
		JPanel result = new JPanel();
		OligoSystemGeneral oligoModel = getOligoModel();
		int output = 0;
		if (oligoModel.nameToInt.get("a") != null) {
			output = oligoModel.nameToInt.get("a");
		}
		double[][] data1 = oligoModel.getTimeSeriesComplexModel();
		int firstPeak = MyUtil.getFirstPeak(data1[output],
				ConstantsSin.skipTime);
		double[][] data2 = new double[data1.length + 1][data1[0].length];
		String[] seqNames = new String[data1.length + 1];
		for (int i = 0; i < data1.length; i++) {
			seqNames[i] = oligoModel.intToName.get(i);
			if (seqNames[i] == null)
				seqNames[i] = String.valueOf(i);
			for (int j = 0; j < data1[0].length; j++) {
				data2[i][j] = data1[i][j];
				if (j >= firstPeak
						&& j <= firstPeak + ConstantsSin.period
								* ConstantsSin.numberofperiods) {
					SineFitness evaluator = (SineFitness) config.evaluator;
					data2[data1.length][j] = evaluator.goal(j, firstPeak);
				}
			}
		}
		seqNames[data1.length] = getGoalStringName();
		final PlotExpData demo1 = new PlotExpData("Generation "
				+ this.generationIndex + " Index " + this.individualIndex,
				data2, seqNames, "Time", "Expression");
		result.add(demo1);
		return (result);
	}
}
